package com.health.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.health.common.PageBean;
import com.health.common.PageQueryDTO;
import com.health.domain.CheckItem;
import com.health.mapper.CheckitemMapper;
import com.health.service.CheckitemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
public class CheckitemServiceImpl implements CheckitemService {

    @Autowired
    private CheckitemMapper checkitemMapper;


    @Override
    public PageBean<CheckItem> findPage(PageQueryDTO pageQueryDTO) {
        // 1.校验参数
        if(pageQueryDTO == null
            || pageQueryDTO.getCurrentPage() == null
            || pageQueryDTO.getPageSize() == null) {
            throw new RuntimeException("非法参数");
        }
        // 2.处理业务
        PageHelper.startPage(pageQueryDTO.getCurrentPage(), pageQueryDTO.getPageSize());
        Page<CheckItem> page = checkitemMapper.findCondition(pageQueryDTO.getQueryString());

        // 3.封装数据
        return new PageBean<>(page.getTotal(), page.getResult());
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkitemMapper.findById(id);
    }

    @Override
    public void updateById(CheckItem checkItem) {
        checkitemMapper.updateById(checkItem);
    }

    @Override
    public List<CheckItem> findAll() {
        return checkitemMapper.findAll();
    }

}
